using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using F8Framework.Core;

public class CardItem : BaseItem
{
    private MahjongTile model;
    private GameViewModel _viewModel;

    // 预留给刷新Item使用
    public void Refresh(MahjongTile tile, GameViewModel viewModel)
    {
        model = tile;
        _viewModel = viewModel;
        txt_Name_txt.text = model.Config.Name_CN;

        if (!gameObject.activeSelf)
        {
            gameObject.SetActive(true);
        }
    }
    
    public void Clear()
    {
        model = null;
        _viewModel = null;
        txt_Name_txt.text = "";
    }
    
    // OnEnable
    private void OnEnable()
    {

    }
    
    // Awake
    protected override void OnAwake()
    {
        btn_Card_btn.onClick.AddListener(() =>
        {
            _viewModel.PickTile(model);
        });
    }
    
    // Start
    protected override void OnStart()
    {
        
    }
    
    protected override void OnViewTweenInit()
    {
        transform.localScale = Vector3.one * 0.7f;
    }
    
    // 自定义打开界面动画
    protected override void OnPlayViewTween()
    {
        transform.ScaleTween(Vector3.one, 0.1f).SetEase(Ease.Linear).SetOnComplete(OnViewOpen);
    }
    
    // 打开界面动画完成后
    protected override void OnViewOpen()
    {
        
    }
    
    // OnDisable
    private void OnDisable()
    {
        // 在合适的时候清除事件
        base.ClearEventDispatcher();
    }
    
    // 自动获取组件（自动生成，不能删除）
	[SerializeField] private UnityEngine.UI.Button btn_Card_btn;
	[SerializeField] private UnityEngine.UI.Text txt_Name_txt;

#if UNITY_EDITOR
	protected override void SetComponents()
	{
		btn_Card_btn = transform.Find("btn_Card").GetComponent<UnityEngine.UI.Button>();
		txt_Name_txt = transform.Find("txt_Name").GetComponent<UnityEngine.UI.Text>();
	}
#endif
	// 自动获取组件（自动生成，不能删除）
}